using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using InvoiceProject.Models;

namespace InvoiceProject.Controllers
{   
    public class QuotesController : Controller
    {
        private InvoiceProjectContext context = new InvoiceProjectContext();

        //
        // GET: /Quotes/

        public ViewResult Index()
        {
            return View(context.Quotes.Include(quote => quote.InvoiceItems).ToList());
        }

        //
        // GET: /Quotes/Details/5

        public ViewResult Details(long id)
        {
            Quote quote = context.Quotes.Single(x => x.Id == id);
            return View(quote);
        }

        //
        // GET: /Quotes/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Quotes/Create

        [HttpPost]
        public ActionResult Create(Quote quote)
        {
            if (ModelState.IsValid)
            {
                context.Quotes.Add(quote);
                context.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(quote);
        }
        
        //
        // GET: /Quotes/Edit/5
 
        public ActionResult Edit(long id)
        {
            Quote quote = context.Quotes.Single(x => x.Id == id);
            return View(quote);
        }

        //
        // POST: /Quotes/Edit/5

        [HttpPost]
        public ActionResult Edit(Quote quote)
        {
            if (ModelState.IsValid)
            {
                context.Entry(quote).State = EntityState.Modified;
                context.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(quote);
        }

        //
        // GET: /Quotes/Delete/5
 
        public ActionResult Delete(long id)
        {
            Quote quote = context.Quotes.Single(x => x.Id == id);
            return View(quote);
        }

        //
        // POST: /Quotes/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(long id)
        {
            Quote quote = context.Quotes.Single(x => x.Id == id);
            context.Quotes.Remove(quote);
            context.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}